package com.sari.common.service;

import com.google.common.collect.Lists;
import com.sari.common.persistence.BaseDao;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.util.List;

/**
 * Service基类
 * @param <T>
 */
public class BaseService<T> extends BaseDao<T> {

    public void saveObject(T var1){
        super.saveObject(var1);
    }

    public List listBySql(String sql){
        return super.listBySql(sql);
    }

    public void batchUpdate(String[] sql){
        super.batchUpdate(sql);
    }

    public void executeSql(String sql){
        super.executeSql(sql);
    }

    public void updateObject(T var1){
        super.updateObject(var1);
    }

    public Object loadObject(Class var1, Serializable var2){
        return super.loadObject(var1,var2);
    }

    public Object loadObject(Class var1, String var2, Serializable var3){
        return super.loadObject(var1,var2,var3);
    }

    public Object loadObject(Class var1, String var2, String var3){
        return super.loadObject(var1,var2,var3);
    }

    public Object loadObject(String var1, String var2, String var3){
        return super.loadObject(var1,var2,var3);
    }

    public List checkAirport(String airportName){
        String sql = "select id from airport_info where airport_name_cn = ?";
        return super.listBySql(sql,new Object[]{airportName});
    }

    public List checkLounge(String loungeName){
        String sql = "select id from lounge_info where spot_name_cn = ?";
        return super.listBySql(sql,new Object[]{loungeName});
    }

    public List checkRestaurant(String spotName,String airportId){
        String sql = "select id from restaurant_info where spot_name_en = ? and airport_id = ?";
        return super.listBySql(sql,new Object[]{spotName,airportId});
    }

    public void deleteValidObject(String var1, String var2, Serializable var3){
        String hql = "update "+ var1 +" set is_valid=0 where "+var2+"=?";
        super.executeSql(hql,new Object[]{var3});

    }

    /**
     * 日志对象
     */
    protected Logger logger = LoggerFactory.getLogger(getClass());

    protected List<Long> getIdList(String ids) {
        List<Long> idList = Lists.newArrayList();
        if (StringUtils.isNotBlank(ids)) {
            ids = ids.trim().replace("　", ",").replace(" ", ",").replace("，", ",");
            String[] arrId = ids.split(",");
            for (String id : arrId) {
                if (id.matches("\\d*")) {
                    idList.add(Long.valueOf(id));
                }
            }
        }
        return idList;
    }

}
